package com.ocom.amqp.core;

import com.ocom.amqp.builder.AbstractAssemblyBuilder;
import lombok.Data;

/**
 * 如果此类型对象存在于springApplicationContext 容器中
 * 组件会帮助自动创建延时队列
 */
@Data
public class DelayQueue extends BasicExpandAssembly {

    /**
     * 业务名称 用于后续的交换机 队列 命名
     * 确保rabbitmq virtual host 中唯一
     */
    private String businessName;

    private Long expiration;

    private String routingKey;

    /**
     * routingKey 禁止使用模糊匹配
     *
     * @param businessName
     * @param routingKey
     */
    public DelayQueue(String businessName, String routingKey) {
        this(businessName, null, routingKey);
    }

    /**
     * routingKey 禁止使用模糊匹配
     *
     * @param businessName
     * @param expiration
     * @param routingKey
     */
    public DelayQueue(String businessName, Long expiration, String routingKey) {
        this.businessName = businessName;
        this.expiration = expiration;
        this.routingKey = routingKey;
    }


    @Override
    public String getSendExchangeName() {
        return AbstractAssemblyBuilder.DELAY_PREFIX.concat(businessName).concat(AbstractAssemblyBuilder
                .EXCHANGE_SUFFIX);
    }

    @Override
    public String getListenQueueName() {
        return AbstractAssemblyBuilder.DEAD_PREFIX.concat(businessName).concat(AbstractAssemblyBuilder.QUEUE_SUFFIX);
    }

}
